
from model.entitys import get_sync_db, CaseGroup, Case, Status, to_json

class DatabaseHandle:

    def __init__(self):
        self.session = get_sync_db()

    def get_data(self) -> list:
        data_list = []

        case_group_list = self.session.query(CaseGroup).all()
        for case_group in case_group_list:
            case_list = self.session.query(Case).filter(Case.case_group_id == case_group.id).filter(
                Case.enable == Status.VALID).all()

            case_list = to_json(case_list)
            for case in case_list:
                case["current_info"] = {
                    "sheet": case_group.title
                }

            data_list.extend(case_list)
            # data_list += case_list

        self.session.close()

        return data_list





































